package it.osg.pipe.transformers;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Iterator;

import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.core.WhitespaceTokenizerFactory;
import org.apache.lucene.analysis.standard.ClassicTokenizerFactory;
import org.apache.lucene.analysis.standard.UAX29URLEmailTokenizerFactory;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.util.Version;

import it.osg.pipe.core.Transformer;

public class SentenceSplitter extends Transformer {

	public SentenceSplitter(String modName, String conFilePath) {
		super(modName, conFilePath);
	}

	public static void main(String[] args) {
		WhitespaceTokenizerFactory factory = new WhitespaceTokenizerFactory();
		factory.setLuceneMatchVersion(Version.LUCENE_41);	
		FileReader reader;
		try {
			reader = new FileReader("C:/Users/servill7/Desktop/mail/Apertura_chiusura_SDP/AVVIO_SDP/Faq logon  SDP non ci sono connessioni disponibili per tutti gli utenti.msg");

			TokenStream stream = factory.create(reader);
			try {
				stream.reset();
				while(stream.incrementToken()) {
					System.out.println(stream.getAttribute(CharTermAttribute.class).toString());
				}
			} catch (IOException e1) {
				e1.printStackTrace();
			}

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

	}

	@Override
	public ArrayList<String> getOutput(ArrayList<String> input) {

		ArrayList<String> result = new ArrayList<String>();

		Iterator<String> it = input.iterator();
		while (it.hasNext()){

			String currInput = it.next();
			String[] tokens = currInput.split("\\.");
			
			for (int i = 0; i < tokens.length; i++) {
				String currSentence = tokens[i];
				result.add(currSentence);
			}



		}
		return result;
	}
}
